<?php

if (!defined('MOODLE_INTERNAL')) {
    die('Direct access to this script is forbidden.');
}

global $CFG;
require_once($CFG->dirroot . '/blocks/formal_langs/lexical_pattern.php');

class block_formal_langs_lexical_pattern_test extends UnitTestCase {

    public function test_lexer_action_constructor() {
        $action_a = new block_formal_langs_lexer_action('create');
        $action_b = new block_formal_langs_lexer_action('append', 'error msg');

        $this->assertNotNull($action_a);
        $this->assertNotNull($action_b);
        $this->assertIsA($action_a, 'block_formal_langs_lexer_action');
        $this->assertIsA($action_b, 'block_formal_langs_lexer_action');

        $this->assertEqual($action_a->type(), 'create');
        $this->assertEqual($action_b->type(), 'append');

        $this->assertNull($action_a->error_msg());
        $this->assertEqual($action_b->error_msg(), 'error msg');
    }

    public function test_lexer_pattern_constructor_1() {
        $actions = array();
        $actions[] = new block_formal_langs_lexer_action('append');
        $actions[] = new block_formal_langs_lexer_action('create');
        $pattern = new block_formal_langs_lexer_pattern(5, 'ID', '[a-zA-Z_][a-zA-Z0-9_]+', $actions);

        $this->assertNotNull($pattern);
        $this->assertIsA($pattern, 'block_formal_langs_lexer_pattern');

        $this->assertEqual($pattern->actions(), $actions);
        $this->assertEqual($pattern->name(), 'ID');
        $this->assertEqual($pattern->number(), 5);
        $this->assertEqual($pattern->activecondition(), 'INITIAL');
        $this->assertNull($pattern->nextcondition());
        $this->assertEqual($pattern->regexp(), '[a-zA-Z_][a-zA-Z0-9_]+');
    }


    public function test_lexer_pattern_constructor_2() {
        $actions = array();
        $actions[] = new block_formal_langs_lexer_action('append');
        $actions[] = new block_formal_langs_lexer_action('create');
        $pattern = new block_formal_langs_lexer_pattern(5, 'ID', '[a-zA-Z_][a-zA-Z0-9_]+', $actions, 'A', 'B');

        $this->assertNotNull($pattern);
        $this->assertIsA($pattern, 'block_formal_langs_lexer_pattern');

        $this->assertEqual($pattern->actions(), $actions);
        $this->assertEqual($pattern->name(), 'ID');
        $this->assertEqual($pattern->number(), 5);
        $this->assertEqual($pattern->activecondition(), 'A');
        $this->assertEqual($pattern->nextcondition(), 'B');
        $this->assertEqual($pattern->regexp(), '[a-zA-Z_][a-zA-Z0-9_]+');
    }
}
 ?>